import { isRequired } from '@/components/Form/fieldType/rules/utils'

/**
 * @export 字符串校验
 * @param {*} { max_length, min_length } 最大长度 最小长度
 * @return {*}
 */
export function validateStrLen ({ min_length, max_length }, message) {
  return {
    validator (rule, value, callback = (e) => e) {
      const is_length = (
        (((value.length < min_length) && min_length !== 0) ||
          ((value.length > max_length) && max_length !== 0)) &&
          isRequired(value)
      )
      if (is_length) {
        const mesg = `请${message}长度为${min_length}-${max_length}！`
        callback(mesg)
        return new Error(mesg)
      }

      callback()
      return true
    },
  }
}

export function validatePass () {}
